<?php
header('Content-Type:application/json;charset=utf-8');
$raw=file_get_contents('php://input');
$raw=json_decode($raw,true);
$id=$raw['id'];
$gid=$raw['gid'];
$name=$raw['name'];

if($id!='' && $gid!='' && $name!=''){
    if(file_exists("名称/分类/$id")){
        
        if($id == $gid){
            file_put_contents("名称/分类/$gid",$name);
            $arr=array('msg'=>'成功','content'=>'修改成功！');
            echo json_encode($arr,JSON_UNESCAPED_UNICODE);
        }else{
            //判断gid是否重复
            if(!file_exists("名称/分类/$gid")){
                @rename("分类/$id","分类/$gid");
                unlink("名称/分类/$id");
                file_put_contents("名称/分类/$gid",$name);
                $arr=array('msg'=>'成功','content'=>'修改成功！');
                echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            }else{
                $arr=array('msg'=>'失败','content'=>'被修改的ID已存在！');
                echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            }
        }
    }else{
        $arr=array('msg'=>'失败','content'=>'该ID不存在！');
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
}else{
    $arr=array('msg'=>'失败','content'=>'参数不完整！');
    echo json_encode($arr,JSON_UNESCAPED_UNICODE);
}
